package com.school.ArrayListStudent;

import java.util.ArrayList;
import java.util.Scanner;

public class ArrayListStudent2keyboard {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        Scanner sc=new Scanner(System.in);

        for (int i=0;i<3;i++) {
            Student stu=new Student();
            System.out.println("请输入学生姓名：");
            String name=sc.next();
            System.out.println("请输入学生年龄：");
            int age=sc.nextInt();

            //把name和age封装到Student对象中
            stu.setName(name);
            stu.setAge(age);

            //把Student对象添加到集合中
            students.add(stu);
        }

        System.out.println(students.size());
        for(int i=0;i<students.size();i++){
            Student stu1=students.get(i);
            System.out.println(stu1.getName()+" "+stu1.getAge());
        }


    }
}
